package com.soho.mdi;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleListener;
import org.osgi.framework.ServiceRegistration;

import com.soho.mdi.common.MDIContext;
import com.soho.mdi.common.MDIDesktop;

public class Activator implements BundleActivator,BundleListener,MDIContext {
	private ServiceRegistration serviceReg=null;
	/*
	 * (non-Javadoc)
	 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
	 */
	public void start(BundleContext context) throws Exception {
		//File dir = new File("c:\\test_files");
		//new BundleDetector(context).detect(dir);
		//serviceReg=context.registerService(BundleDetector.class.getName(), new BundleDetector(context), null);
		String symbolicName = context.getBundle().getSymbolicName();
		context.registerService(symbolicName, this, null);
		context.addBundleListener(this);
	}

	/*
	 * (non-Javadoc)
	 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
	 */
	public void stop(BundleContext context) throws Exception {
		/*
		if (null != serviceReg){
			serviceReg.unregister();
		}*/
	}

	public void bundleChanged(BundleEvent event) {
		switch (event.getType()){
		case BundleEvent.INSTALLED:	
			System.out.println("Installed...");
			break;
		case BundleEvent.STARTED:
			System.out.println("Started...");
			break;			
		case BundleEvent.STOPPED:
			System.out.println("Stopped...");
			break;			
		case BundleEvent.UNINSTALLED:
			System.out.println("UNINSTALLED...");
			break;			
		case BundleEvent.UPDATED:
			System.out.println("UPDATED...");
			break;			
		}
		
	}

	public void register(MDIDesktop desktop) {
		System.out.println("Register Desktop...");
		
	}

}
